package com.ruoyi.city.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.city.domain.HouseCity;
import com.ruoyi.city.service.IHouseCityService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 城市信息Controller
 * 
 * @author ruoyi
 * @date 2025-09-10
 */
@RestController
@RequestMapping("/city")
public class HouseCityController extends BaseController
{
    @Autowired
    private IHouseCityService houseCityService;

    /**
     * 查询城市信息列表
     */
    @RequiresPermissions("city:city:list")
    @GetMapping("/list")
    public TableDataInfo list(HouseCity houseCity)
    {
        startPage();
        List<HouseCity> list = houseCityService.selectHouseCityList(houseCity);
        return getDataTable(list);
    }

    /**
     * 修改城市状态
     * @return
     */
    @PostMapping("/changStatus")
    public AjaxResult changsStatus(@RequestBody HouseCity houseCity){

        return AjaxResult.success(houseCityService.changStatus(houseCity));
    }

    /**
     * 导出城市信息列表
     */
    @RequiresPermissions("city:city:export")
    @Log(title = "城市信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseCity houseCity)
    {
        List<HouseCity> list = houseCityService.selectHouseCityList(houseCity);
        ExcelUtil<HouseCity> util = new ExcelUtil<HouseCity>(HouseCity.class);
        util.exportExcel(response, list, "城市信息数据");
    }

    /**
     * 获取城市信息详细信息
     */
    @RequiresPermissions("city:city:query")
    @GetMapping(value = "/{cityId}")
    public AjaxResult getInfo(@PathVariable("cityId") Integer cityId)
    {
        return success(houseCityService.selectHouseCityByCityId(cityId));
    }

    /**
     * 新增城市信息
     */
    @RequiresPermissions("city:city:add")
    @Log(title = "城市信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseCity houseCity)
    {
        return toAjax(houseCityService.insertHouseCity(houseCity));
    }

    /**
     * 修改城市信息
     */
    @RequiresPermissions("city:city:edit")
    @Log(title = "城市信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseCity houseCity)
    {
        return toAjax(houseCityService.updateHouseCity(houseCity));
    }

    /**
     * 删除城市信息
     */
    @RequiresPermissions("city:city:remove")
    @Log(title = "城市信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cityIds}")
    public AjaxResult remove(@PathVariable Integer[] cityIds)
    {
        return toAjax(houseCityService.deleteHouseCityByCityIds(cityIds));
    }
}
